/*
 * Adara WebCam TimeLapse capture software.
 * Copyright (C) 2012 AdaraProjectTeam
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package adara.core.process;

import java.io.File;
import java.util.Observable;
import java.util.Observer;

import adara.core.Device;

import com.lti.civil.CaptureStream;

/**
 * This is the implementation of the processing based on number of images to be
 * obtained from web camera.
 * @author Andrei Ermicioi (aka erani) <andrei.ermicioi@gmail.com>
 *
 */
public class CountProcess extends Process implements Observer {
	
	private int count = 0;
	private int done = 0;
	
	public CountProcess(Device device, int timegap, File storage,
			CaptureStream stream) {
		super(device, timegap, storage, stream);
		
		this.addObserver(this);
	}
	
	/**
	 * Launch the process and set the number of images to be taken.
	 * @param count
	 */
	public void launch(int count) {
		this.count = count;
		this.launch();
	}
	
	@Override
	protected boolean shouldStop() {
		return (done >= count) ? true : false;
	}

	@Override
	public void update(Observable caller, Object image) {
		done++;
	}

	@Override
	public int getProgressStatus() {
		return done * 100 / count;
	}

}
